//
//  GalleryDelegate.m
//  FileLockerPro
//
//  Created by SDSL-3 on 7/10/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "GalleryDelegate.h"
#import "AssetManager.h"

@implementation GalleryDelegate
@synthesize images;
@synthesize gallery;


- (void)dealloc {
    self.images = nil;
    self.gallery = nil;
    [super dealloc];
}

#pragma mark - FGalleryViewControllerDelegate Methods


- (int)numberOfPhotosForPhotoGallery:(FGalleryViewController *)gallery
{
    if(images != nil){
        return [images count];
    }
    return 0;
}


- (FGalleryPhotoSourceType)photoGallery:(FGalleryViewController *)gallery sourceTypeForPhotoAtIndex:(NSUInteger)index
{
    return FGalleryPhotoSourceTypeLocal;
}


- (NSString*)photoGallery:(FGalleryViewController *)gallery captionForPhotoAtIndex:(NSUInteger)index
{
    return nil;
}


- (NSString*)photoGallery:(FGalleryViewController*)gallery filePathForPhotoSize:(FGalleryPhotoSize)size atIndex:(NSUInteger)index {
    return [images objectAtIndex:index];
}

- (NSString*)photoGallery:(FGalleryViewController *)gallery urlForPhotoSize:(FGalleryPhotoSize)size atIndex:(NSUInteger)index {
    return [images objectAtIndex:index];
}

- (void)handleTrashButtonTouch:(id)sender {
    // here we could remove images from our local array storage and tell the gallery to remove that image
    // ex:
    //[localGallery removeImageAtIndex:[localGallery currentIndex]];
    
    AssetManager *am = [[AssetManager alloc] init];
    [am deleteFile:[self.images objectAtIndex:[self.gallery currentIndex]]];
    [self.images removeObjectAtIndex:[self.gallery currentIndex]];
    [self.gallery reloadGallery];
}


- (void)handleEditCaptionButtonTouch:(id)sender {
    // here we could implement some code to change the caption for a stored image
    AssetManager *am = [[AssetManager alloc] init];
    [am exportImage:[self.images objectAtIndex:[self.gallery currentIndex]]];
    [am deleteFile:[self.images objectAtIndex:[self.gallery currentIndex]]];
    [self.images removeObjectAtIndex:[self.gallery currentIndex]];
    [self.gallery reloadGallery];

}

@end
